<template>
  <div>
    <a-select
      :placeholder="placeholder"
      :disabled="disabled"
      :value="value"
      @change="handleChange"
      :mode="multiple ? 'multiple' : 'default'"
      :showSearch="true"
      :filterOption="filterOption"
      allowClear
      :style="{ width: '100%' }"
    >
      <a-select-option v-for="(item, index) in dataSource" :key="index" :value="item.id">
        {{ item.purchaseNo }}
      </a-select-option>
    </a-select>
  </div>
</template>

<script>
import { getAction } from '@/api/manage'

export default {
  name: 'JSelectPurchaseOrder',
  props: {
    placeholder: {
      type: String,
      default: '请选择采购单',
      required: false
    },
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    value: {
      type: String,
      required: false
    },
    multiple: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      dataSource: []
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    loadData() {
      getAction('/wms/wmsPurchaseOrder/listAll', {}).then(res => {
        if (res.success) {
          this.dataSource = res.result || []
        }
      })
    },
    handleChange(value) {
      this.$emit('change', value)
      this.$emit('input', value)
    },
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    }
  }
}
</script> 